package com.smx.sync.scheduled;

import com.smx.sync.mapper.SyncConfigMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * RemoveSyncTaskLogScheduled
 *
 * @author 廖功旺
 * @version 1.0
 * @since 2025/6/30 9:33
 */
@Slf4j
@Component
public class RemoveSyncTaskLogScheduled {

    @Autowired
    private SyncConfigMapper syncConfigMapper;

    /**
     * 每日0点15分清理30天前的同步任务日志
     */
    @Scheduled(cron = "0 15 0 * * ?")
    public void removeSyncTaskLog() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        log.info("开始清理30天前的同步任务日志@{}", sdf.format(new Date()));
        try {
            syncConfigMapper.removeSyncTaskLog();
            syncConfigMapper.removeSyncTaskDaily();
            log.info("清理30天前的同步任务日志完成@{}", sdf.format(new Date()));
        } catch (Exception e) {
            log.error("清理30天前的同步任务日志异常@{}", sdf.format(new Date()), e);
        }
    }
}
